#include "mqtt_subscriber.h"
#include <iostream>
#include <string>

int main(int argc, char* argv[]) {
    std::string topic = "sensors/temperature";
    
    // 简单的命令行参数处理
    if (argc > 1) {
        topic = argv[1];
    }
    
    std::cout << "=== MQTT 订阅者演示 ===" << std::endl;
    std::cout << "订阅主题: " << topic << std::endl;
    std::cout << "Broker: tcp://192.168.202.1:1883" << std::endl;
    std::cout << "按 Ctrl+C 退出" << std::endl;
    std::cout << "======================" << std::endl;

    // 创建订阅者
    MQTTSubscriber subscriber("tcp://192.168.202.1:1883", "demo_subscriber");
    
    // 连接
    if (!subscriber.Connect()) {
        std::cerr << "连接失败!" << std::endl;
        return 1;
    }

    // 订阅主题
    if (!subscriber.Subscribe(topic)) {
        std::cerr << "订阅失败!" << std::endl;
        subscriber.DisConnect();
        return 1;
    }

    // 等待消息
    subscriber.WaitForMessages(0);  // 无限等待

    // 断开连接
    subscriber.DisConnect();
    
    return 0;
}